{include file="common/_meta" /}
<title></title>
</head>

<body>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>代理管理 <span class="c-gray en">&gt;</span> 代理列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-c">
            <form class="Huiform" method="get" action="">
                <!-- 代理类型
                <span class="select-box inline">
                <select name="dltype" class="select">
                    <option value="">全部</option> 
                    <option value="1">市级代理</option> 
                    <option value="2">区域代理</option>
                </select> -->
                </span> 所在省市：
                <span class="select-box inline">
                <select name="province" class="select">
                    <option value="">--全部--</option>
                    {volist name="province" id='vo'}
                        <option value="{$vo.p_code}">{$vo.name}</option>
                    {/volist}
                </select>
                </span>
                <input type="text" class="input-text" style="width:250px" placeholder="代理姓名、手机号" id="" name="keywords" value="{$Request.get.keywords|default=''}">
                <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <a class="btn btn-primary radius" id="agentAdd" href="javascript:;"><i class="Hui-iconfont"></i> 添加代理</a>
            <span class="r">共有数据：<strong>{$list->total()}</strong> 条</span></div>
        <div class="mt-20">
            <table class="table table-border  table-hover table-bg table-sort">
                <thead>
                    <tr class="text-c">
                        <th width="25">
                            <input type="checkbox" name="" value="">
                        </th>
                        <th>编号</th>
                        <th>代理人</th>
                        <th>代理省市</th>
                        <th>信息查看</th>
                        <!-- <th>注册时间</th> -->
                        <th>状态</th>
                        <th width="10%">操&nbsp;&nbsp;&nbsp;&nbsp;作</th>
                    </tr>
                </thead>
                <tbody>
                    {volist name='list' id="vo"}
                    <tr class="text-c">
                        <td>
                            <input type="checkbox" value="1" name="">
                        </td>
                        <td>{$i}</td>
                        <td>{$vo.name} : {$vo.tel}</td>
                        <td>{$vo.mer_name}</td>
                        <td>
                            <a href="{:url('User/index')}?page=1&province={$vo.province}&city={$vo.city}"> 区域玩家</a>
                        </td>
                        <!-- <td>{$vo.create_time}</td> -->
                        <td class="td-status">
                            {if condition="$vo.status eq 1"}
                            <span class="label label-success radius">已启用</span> {else/}
                            <span class="label label-error radius">已禁用</span> {/if}
                        </td>
                        <td class="td-manage">
                            <a style="text-decoration:none" onClick="agentRm(this,{$vo.id})" href="javascript:;" title="移除此代理"><i class="Hui-iconfont">&#xe631;</i></a> &nbsp;&nbsp;&nbsp;
                            <a style="text-decoration:none" onClick="agentEdit(this,{$vo.id})" href="javascript:;" title="编辑此代理"><i class="Hui-iconfont">&#xe647;</i></a>
                        </td>
                    </tr>
                    {/volist}
                </tbody>
            </table>
            <div class="pages" style="margin:20px;float: right; ">{$list->render()}</div>
        </div>
        <!-- 添加、修改代理 -->
        <div id="agent_add" class="modal fade" style="margin: 0 auto;" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content radius">
                    <div class="modal-header">
                        <h3 class="modal-title"></h3>
                        <a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
                    </div>
                    <div class="modal-body">
                        <article class="page-container" style="padding-right: 10%;">
                            <form action="" method="post" class="form form-horizontal" id="form-agent-add">
                                <div class="row cl hidden">
                                    <label class="form-label col-xs-4 col-sm-3"></label>
                                    <div class="formControls col-xs-8 col-sm-9">
                                        <input type="text" name="id" class="input-text" placeholder="" autocomplete="off" id="id" value="0">
                                        <input type="text" name="uid" class="input-text" placeholder="" autocomplete="off" id="uid" value="0">
                                    </div>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4 col-sm-3">手机号</label>
                                    <div class="formControls col-xs-8 col-sm-9">
                                        <input type="text" name="tel" class="input-text" placeholder="" autocomplete="off" id="tel" disabled="true">
                                    </div>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4 col-sm-3">姓名</label>
                                    <div class="formControls col-xs-8 col-sm-9">
                                        <input type="text" name="name" class="input-text" placeholder="" autocomplete="off" id="name" disabled="true">
                                    </div>
                                </div>
                               
                                <!-- <div class="row cl">
                                    <label class="form-label col-xs-4 col-sm-3">代理类型</label>
                                    <div class="formControls col-xs-8 col-sm-9">
                                        <div class="radio-box">
											<input name="dltype" type="radio" value="1" id="">
											<label for="sex-1">市级代理</label>
										</div>
										<div class="radio-box">
											<input type="radio" value="2" id="" name="dltype">
											<label for="sex-2" >区域代理</label>
										</div>
                                    </div>
                                </div> -->
                                <div class="row cl">
                                    <label class="form-label col-xs-4 col-sm-3">代理城市</label>
                                    <div class="formControls col-xs-8 col-sm-9">
                                        <span class="select-box inline">
									<select name="province" class="select" id="province">
										{volist name="province" id="vo"}
											<option value="{$vo.p_code}">{$vo.name}</option>
										{/volist}
									</select>
									</span> &nbsp;
                                        <span class="select-box inline">
									<select name="city" class="select" id="city"> 
										<option value="">---</option>
									</select>
									</span> &nbsp;
                                    <span class="select-box inline" style="display: none;" >
									<select name="dist" class="select" id="dist" > 
										<option value="">---</option>
									</select>
									</span>
                                    </div>
                                </div>
                                <div class="row cl">
                                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                                        <input class="btn btn-primary radius" type="submit" value="提交">
                                        <input class="btn btn-primary radius" type="reset" style="display: none;" id="rst">
                                    </div>
                                </div>
                            </form>
                        </article>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {include file="common/_footer" /}
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript">
    $('select[name="province"]').val({$Request.get.province});
    // 
    $(":radio").change(function(event) {
	   var obj = this;
	   if ($(obj).val() == 1) {
	        $('#dist').addClass('hidden');
	   } else {
	        $('#dist').removeClass('hidden');
	   }
	});
	// 

    $("#province").change(function() {
        var code = $(this).val();
        $.get("{:url('getCity')}", { 'p_code': code }).success(function(data) {
            var html = '<option value="0">---</option>';
            $.each(data.city, function(index, value) {
                html += '<option value="' + value.c_code + '">' + value.name + '</option>';
            });
            $('#city').html(html);
            $('#dist').html('<option value="0">---</option>');
        });
    });

    // $("#city").change(function() {
    //     var code = $(this).val();
    //     $.get("{:url('getDist')}", { 'c_code': code }).success(function(data) {
    //         var html = '';
    //         $.each(data.dist, function(index, value) {
    //             html += '<option value="' + value.code + '">' + value.name + '</option>';
    //         });
    //         $('#dist').html(html);
    //     });
    // });
    

    // 添加代理
    $("#form-agent-add").find('input:submit').click(function() {

        $.post("{:url('Agent/addAgent')}", $("#form-agent-add").serialize()).success(function(data) {
            layer.msg(data.msg);
            if (data.code) {
                setTimeout(function() {
                    history.go(0);
                }, 1000);
            }
        });
        return false;
    });

    // 移除此代理
    function agentRm(obj, id) {
        layer.confirm('确认移除此代理吗', function(index) {
            $.ajax({
                type: 'POST',
                url: "{:url('Agent/index')}?act=rm",
                data: { 'id': id },
                dataType: 'json',
                success: function(data) {
                    layer.msg(data.msg, { icon: 6, time: 1000 });
                    if (data.code) {
                        setTimeout(function() {
                            history.go(0);
                        }, 500);
                    }
                },
                error: function(data) {
                    console.log(data.msg);
                },
            });
        });
    }

    // 代理编辑
    function agentEdit(obj, id) {
        $("#agent_add").modal("show");
        $.post("{:url('Agent/index')}?act=get", { id: id }, function(data) {
            if (data) {
            	// $(':radio[value='+data.dltype+']').attr('checked',true);
            	$('#id').val(data.id);
                $('#uid').val(data.uid);
                $('#name').val(data.name);
                $('#tel').val(data.tel);
                if (data.dltype == 1) {
                	$('#dist').addClass('hidden');
                }
            }
        });
    }

    $('#agentAdd').click(function () {
        $('#rst').click();
        $('#tel').attr('disabled', false);
        $('#name').attr('disabled', false);
        $("#agent_add").modal("show");
    })


    </script>
</body>

</html>